/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Aplicacion.java
 *
 * Created on 08-11-2010, 08:46:58 PM
 */

package cl.hora;
/*


*/

/**/
		

import cl.jaudio.basico.AudioFile;
import cl.jaudio.basico.Reproductor;
import cl.util.*;
import cl.util.archivos.Archivo;
import cl.util.archivos.Ejecutar;
import cl.util.fecha.Fecha;
import cl.util.formulario.Redimensionar;
import cl.util.hora.Hora;
import cl.util.hora.HoraAudio;
import cl.util.mensajes.Mensajes;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import transparentWindows.AWTUtilitiesWrapper;
import xml.analizador.dom.JespXML;
import xml.analizador.dom.modelo.Tag;

/**
 *
 * @author pato
 */
public class Aplicacion extends javax.swing.JFrame {
    private HHora hHora = new HHora();
    private HBeep hBeep = new HBeep();
    private HGpu hgpu = new HGpu();
    public static Config config;
    //Objeto utilizado para poder rastrear el punto cuando queramos mover la ventana principal
    private Point punto; 
    private List<K.Componente> componentes = new ArrayList<>();
    private AppSystemtray app;


    /** Creates new form Aplicacion */
    public Aplicacion() {
        initComponents();
        getConfiguracionDesdeXML();
        inicializarComponentesGraficos();
        setColorEnPanelHora();
        iniciarHilos();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        form_tema = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        lblfbm = new javax.swing.JLabel();
        lbltit = new javax.swing.JLabel();
        lblfnd = new javax.swing.JLabel();
        lblhor = new javax.swing.JLabel();
        lblfec = new javax.swing.JLabel();
        lblfbh = new javax.swing.JLabel();
        lblfbs = new javax.swing.JLabel();
        lblsoh = new javax.swing.JLabel();
        lblbarmin = new javax.swing.JLabel();
        lblbarhor = new javax.swing.JLabel();
        lblbarseg = new javax.swing.JLabel();
        op1 = new javax.swing.JRadioButton();
        op2 = new javax.swing.JRadioButton();
        op3 = new javax.swing.JRadioButton();
        op4 = new javax.swing.JRadioButton();
        op5 = new javax.swing.JRadioButton();
        op6 = new javax.swing.JRadioButton();
        op7 = new javax.swing.JRadioButton();
        op8 = new javax.swing.JRadioButton();
        op9 = new javax.swing.JRadioButton();
        op10 = new javax.swing.JRadioButton();
        op11 = new javax.swing.JRadioButton();
        lblgpu = new javax.swing.JLabel();
        op12 = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        selector = new javax.swing.JColorChooser();
        jButton7 = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        Recordatorio = new javax.swing.JFrame();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        cboHora = new javax.swing.JComboBox();
        cboMinuto = new javax.swing.JComboBox();
        cboSegundo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        fechaChooser = new datechooser.beans.DateChooserCombo();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        men = new javax.swing.JTextArea();
        form_log = new javax.swing.JFrame();
        jScrollPane2 = new javax.swing.JScrollPane();
        areaMensajes = new javax.swing.JTextArea();
        jButton5 = new javax.swing.JButton();
        form_opa = new javax.swing.JFrame();
        jPanel4 = new javax.swing.JPanel();
        nivelOpacidad = new javax.swing.JSlider();
        poropa = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        panel = new javax.swing.JPanel();
        fecha = new javax.swing.JLabel();
        lblx = new javax.swing.JLabel();
        lblso = new javax.swing.JLabel();
        gpu = new javax.swing.JLabel();
        lblAudio = new javax.swing.JLabel();
        hora = new javax.swing.JLabel();
        barraHora = new javax.swing.JProgressBar();
        barraSegundo = new javax.swing.JProgressBar();
        barraMinuto = new javax.swing.JProgressBar();

        form_tema.getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Aplicar Color a"));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblfbm.setBackground(new java.awt.Color(255, 255, 255));
        lblfbm.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblfbm.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfbm.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblfbm.setOpaque(true);
        jPanel1.add(lblfbm, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, 120, 20));

        lbltit.setBackground(new java.awt.Color(255, 255, 255));
        lbltit.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lbltit.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbltit.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lbltit.setOpaque(true);
        jPanel1.add(lbltit, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 120, 20));

        lblfnd.setBackground(new java.awt.Color(255, 255, 255));
        lblfnd.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblfnd.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfnd.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblfnd.setOpaque(true);
        jPanel1.add(lblfnd, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 120, 20));

        lblhor.setBackground(new java.awt.Color(255, 255, 255));
        lblhor.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblhor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblhor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblhor.setOpaque(true);
        jPanel1.add(lblhor, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 120, 20));

        lblfec.setBackground(new java.awt.Color(255, 255, 255));
        lblfec.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblfec.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfec.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblfec.setOpaque(true);
        jPanel1.add(lblfec, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 120, 20));

        lblfbh.setBackground(new java.awt.Color(255, 255, 255));
        lblfbh.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblfbh.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfbh.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblfbh.setOpaque(true);
        jPanel1.add(lblfbh, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 120, 20));

        lblfbs.setBackground(new java.awt.Color(255, 255, 255));
        lblfbs.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblfbs.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfbs.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblfbs.setOpaque(true);
        jPanel1.add(lblfbs, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 230, 120, 20));

        lblsoh.setBackground(new java.awt.Color(255, 255, 255));
        lblsoh.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblsoh.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblsoh.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblsoh.setOpaque(true);
        jPanel1.add(lblsoh, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 350, 120, 20));

        lblbarmin.setBackground(new java.awt.Color(255, 255, 255));
        lblbarmin.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblbarmin.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblbarmin.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblbarmin.setOpaque(true);
        jPanel1.add(lblbarmin, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 290, 120, 20));

        lblbarhor.setBackground(new java.awt.Color(255, 255, 255));
        lblbarhor.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblbarhor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblbarhor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblbarhor.setOpaque(true);
        jPanel1.add(lblbarhor, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 260, 120, 20));

        lblbarseg.setBackground(new java.awt.Color(255, 255, 255));
        lblbarseg.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblbarseg.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblbarseg.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblbarseg.setOpaque(true);
        jPanel1.add(lblbarseg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, 120, 20));

        op1.setText("Título de la Ventana");
        op1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op1ActionPerformed(evt);
            }
        });
        jPanel1.add(op1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 50, -1, -1));

        op2.setText("Fondo");
        op2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op2ActionPerformed(evt);
            }
        });
        jPanel1.add(op2, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 80, -1, -1));

        op3.setText("Hora");
        op3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op3ActionPerformed(evt);
            }
        });
        jPanel1.add(op3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 110, -1, -1));

        op4.setText("Fecha");
        op4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op4ActionPerformed(evt);
            }
        });
        jPanel1.add(op4, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 140, -1, -1));

        op5.setText("Fondo Barra Hora");
        op5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op5ActionPerformed(evt);
            }
        });
        jPanel1.add(op5, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 170, -1, -1));

        op6.setText("Fondo Barra Minuto");
        op6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op6ActionPerformed(evt);
            }
        });
        jPanel1.add(op6, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 200, -1, -1));

        op7.setText("Fondo Barra Segundo");
        op7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op7ActionPerformed(evt);
            }
        });
        jPanel1.add(op7, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 230, -1, -1));

        op8.setText("Barra Hora");
        op8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op8ActionPerformed(evt);
            }
        });
        jPanel1.add(op8, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 260, -1, -1));

        op9.setText("Barra Minuto");
        op9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op9ActionPerformed(evt);
            }
        });
        jPanel1.add(op9, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 290, -1, -1));

        op10.setText("Barra Segundo");
        op10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op10ActionPerformed(evt);
            }
        });
        jPanel1.add(op10, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 320, -1, -1));

        op11.setText("Título SO Huésped ");
        op11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op11ActionPerformed(evt);
            }
        });
        jPanel1.add(op11, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 350, -1, -1));

        lblgpu.setBackground(new java.awt.Color(255, 255, 255));
        lblgpu.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        lblgpu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblgpu.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lblgpu.setOpaque(true);
        jPanel1.add(lblgpu, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 380, 120, 20));

        op12.setText("GPU");
        op12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                op12ActionPerformed(evt);
            }
        });
        jPanel1.add(op12, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 380, -1, 20));

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 3, 11)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Color Actual");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 120, 30));

        jButton2.setText("Desmarcar Todo");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 400, 160, -1));

        jButton3.setText("Desmarcar Todo");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 20, 160, -1));

        form_tema.getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 340, 440));

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Selección de Color"));
        jPanel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jPanel6MouseReleased(evt);
            }
        });
        jPanel6.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        selector.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel6.add(selector, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 440, 380));

        jButton7.setText("Aplicar Colores");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 400, 170, -1));

        form_tema.getContentPane().add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 0, 470, 440));

        jButton1.setText("Agregar Recordatorio");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        Recordatorio.getContentPane().add(jButton1, java.awt.BorderLayout.PAGE_END);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Fecha y Hora"));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cboHora.setEditable(true);
        cboHora.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));
        jPanel2.add(cboHora, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 50, -1));

        cboMinuto.setEditable(true);
        cboMinuto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));
        jPanel2.add(cboMinuto, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 80, 50, -1));

        cboSegundo.setEditable(true);
        cboSegundo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));
        jPanel2.add(cboSegundo, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 80, 50, -1));

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText(":");
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 80, 20, 20));

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText(":");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 80, 10, 20));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("   Hora      :   Minuto   :  Segundo");
        jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 200, -1));

        fechaChooser.setNothingAllowed(false);
        jPanel2.add(fechaChooser, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, 160, -1));

        Recordatorio.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Mensaje de Recordatorio"));
        jPanel3.setLayout(new java.awt.BorderLayout());

        men.setColumns(20);
        men.setLineWrap(true);
        men.setRows(5);
        men.setWrapStyleWord(true);
        jScrollPane1.setViewportView(men);

        jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        Recordatorio.getContentPane().add(jPanel3, java.awt.BorderLayout.LINE_END);

        areaMensajes.setColumns(20);
        areaMensajes.setEditable(false);
        areaMensajes.setRows(5);
        jScrollPane2.setViewportView(areaMensajes);

        form_log.getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jButton5.setText("Detener Sonido de Alarma");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        form_log.getContentPane().add(jButton5, java.awt.BorderLayout.PAGE_END);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Porcentaje de Opacidad"));
        jPanel4.setLayout(new java.awt.BorderLayout());

        nivelOpacidad.setMinimum(1);
        nivelOpacidad.setPaintLabels(true);
        nivelOpacidad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                nivelOpacidadMousePressed(evt);
            }
        });
        nivelOpacidad.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                nivelOpacidadMouseDragged(evt);
            }
        });
        nivelOpacidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                nivelOpacidadKeyReleased(evt);
            }
        });
        jPanel4.add(nivelOpacidad, java.awt.BorderLayout.CENTER);

        poropa.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        poropa.setText("xx%");
        jPanel4.add(poropa, java.awt.BorderLayout.LINE_START);

        jButton6.setText("Aceptar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton6, java.awt.BorderLayout.LINE_END);

        form_opa.getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JReloj");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFocusCycleRoot(false);
        setFocusable(false);
        setFocusableWindowState(false);
        setResizable(false);
        setUndecorated(true);
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        panel.setBackground(new java.awt.Color(0, 0, 0));
        panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora Actual", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(255, 0, 0)));
        panel.setForeground(new java.awt.Color(1, 1, 1));
        panel.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
            public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
                panelMouseWheelMoved(evt);
            }
        });
        panel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                panelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                panelMouseEntered(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                panelMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                panelMouseReleased(evt);
            }
        });
        panel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                panelMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                panelMouseMoved(evt);
            }
        });
        panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        fecha.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        fecha.setForeground(new java.awt.Color(255, 255, 0));
        fecha.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        fecha.setText("Fecha");
        panel.add(fecha, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 220, 30));

        lblx.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblx.setForeground(new java.awt.Color(255, 0, 0));
        lblx.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblx.setText("x");
        lblx.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblxMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lblxMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblxMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lblxMouseReleased(evt);
            }
        });
        panel.add(lblx, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 10, 20, 20));

        lblso.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
        lblso.setForeground(new java.awt.Color(255, 255, 0));
        lblso.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblso.setText("SO Huéped: "+System.getProperty("os.name")+" ");
        panel.add(lblso, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 220, 20));

        gpu.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        gpu.setForeground(new java.awt.Color(255, 255, 0));
        gpu.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        gpu.setText("GPU: xx");
        panel.add(gpu, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 60, -1));

        lblAudio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblAudio.setForeground(new java.awt.Color(255, 0, 0));
        lblAudio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblAudio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/megafono.png"))); // NOI18N
        lblAudio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblAudioMouseClicked(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lblAudioMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblAudioMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lblAudioMouseReleased(evt);
            }
        });
        panel.add(lblAudio, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 30, 30));

        hora.setBackground(new java.awt.Color(0, 0, 0));
        hora.setFont(new java.awt.Font("DejaVu Sans", 3, 38)); // NOI18N
        hora.setForeground(new java.awt.Color(255, 255, 0));
        hora.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        hora.setText("11:11:11");
        panel.add(hora, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 240, 50));

        getContentPane().add(panel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 240, 90));

        barraHora.setFont(new java.awt.Font("Tahoma", 0, 9)); // NOI18N
        barraHora.setMaximum(24);
        barraHora.setToolTipText("Hora");
        barraHora.setString("Hora");
        barraHora.setStringPainted(true);
        getContentPane().add(barraHora, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 10, 90));

        barraSegundo.setFont(new java.awt.Font("Tahoma", 0, 9)); // NOI18N
        barraSegundo.setForeground(new java.awt.Color(0, 1, 0));
        barraSegundo.setMaximum(59);
        barraSegundo.setToolTipText("Segundo");
        barraSegundo.setString("Segundo");
        barraSegundo.setStringPainted(true);
        getContentPane().add(barraSegundo, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 260, 10));

        barraMinuto.setFont(new java.awt.Font("Tahoma", 0, 9)); // NOI18N
        barraMinuto.setMaximum(59);
        barraMinuto.setToolTipText("Minuto");
        barraMinuto.setString("Minuto");
        barraMinuto.setStringPainted(true);
        getContentPane().add(barraMinuto, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 0, 10, 90));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
        
    }//GEN-LAST:event_formMouseDragged

    private void panelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMouseDragged
        setCursor(Cursor.MOVE_CURSOR);
        setBounds(evt.getXOnScreen()-(int)punto.getX()-
        (barraHora.getWidth()), evt.getYOnScreen()-(int)punto.getY(), 
        this.getWidth(), this.getHeight());
    }//GEN-LAST:event_panelMouseDragged

    private void panelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMouseClicked
        
    }//GEN-LAST:event_panelMouseClicked

    private void panelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMousePressed
        punto = evt.getPoint();
    }//GEN-LAST:event_panelMousePressed

    private void panelMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMouseReleased
        this.setCursor(Cursor.DEFAULT_CURSOR);
        Point p = new Point(this.getX(), this.getY());
        Actualizar.posicion(p);
    }//GEN-LAST:event_panelMouseReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String mensaje = men.getText().trim();
        String hora2;
        int hOrA,mInUtO,sEgUnDo;


        try{
            hOrA = Integer.parseInt(cboHora.getSelectedItem().toString());
            mInUtO = Integer.parseInt(cboMinuto.getSelectedItem().toString());
            sEgUnDo = Integer.parseInt(cboSegundo.getSelectedItem().toString());

            if(hOrA < 0 || hOrA > 23){
                Mensajes.mensajeError("Error en la Fecha. Ingrese una Hora correcta");
            }else if(mInUtO < 0|| mInUtO > 59){
                Mensajes.mensajeError("Error en la Fecha. Ingrese un Minuto correcto");
            }else if(sEgUnDo < 0 || sEgUnDo > 59){
                Mensajes.mensajeError("Error en la Fecha. Ingrese un Segundo correcto");
            }else{
                hora2 = hOrA + ":" + Hora.cambiar(mInUtO) + ":" + Hora.cambiar(sEgUnDo);
                String fec;
                fec = Fecha.cambiarFecha(fechaChooser.getText(), false);
                
                
                addRecordatorioToXML(new Recordatorio(fec, mensaje, hora2));
                limpiarFormRecordatorio();
            }
        }catch(NumberFormatException e){
            Mensajes.mensajeError("Error en la Fecha. Se aceptan solo numeros");
        }

//        System.out.println(f.getDiferenciaEnDias(f.getDia()+"-"+f.getNumeroDeMes()+"-"+f.getAño(), f.cambiarFecha(fechaChooser.getText())));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        this.hBeep.setEstado(false);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void panelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMouseEntered
        
    }//GEN-LAST:event_panelMouseEntered

    private void panelMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_panelMouseWheelMoved
        
    }//GEN-LAST:event_panelMouseWheelMoved

    private void panelMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelMouseMoved
        if((evt.getX() > 210 && evt.getX() < 230) && (evt.getY() > 10 && evt.getY() < 30)){
            lblx.setVisible(true);
        }else{
            lblx.setVisible(false);
        }
    }//GEN-LAST:event_panelMouseMoved

    private void lblxMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblxMouseReleased
//        lblx.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        
       
    }//GEN-LAST:event_lblxMouseReleased

    private void lblxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblxMouseClicked
//        lblx.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        int op = Mensajes.mensajePreguntaSiNo
                ("¿Esta seguro que desea Salir de la Aplicación JReloj?");
        if(op==Mensajes.si){
            System.exit(0);
        }
    }//GEN-LAST:event_lblxMouseClicked

    private void lblxMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblxMousePressed
//        lblx.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    }//GEN-LAST:event_lblxMousePressed

    private void lblxMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblxMouseExited
//        lblx.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
    }//GEN-LAST:event_lblxMouseExited

    private void nivelOpacidadMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nivelOpacidadMouseDragged
        setPorcentajeTransparencia((float)nivelOpacidad.getValue());
    }//GEN-LAST:event_nivelOpacidadMouseDragged

    private void nivelOpacidadMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nivelOpacidadMousePressed
        setPorcentajeTransparencia((float)nivelOpacidad.getValue());
    }//GEN-LAST:event_nivelOpacidadMousePressed

    private void nivelOpacidadKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nivelOpacidadKeyReleased
        setPorcentajeTransparencia((float)nivelOpacidad.getValue());
    }//GEN-LAST:event_nivelOpacidadKeyReleased

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        form_opa.setVisible(false);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jPanel6MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel6MouseReleased
//System.out.println("erwer");        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel6MouseReleased

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        for(K.Componente com: componentes){
            establecerColor(com);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void op1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op1ActionPerformed
        agregarComponenteAlaLista(op1, K.Componente.TITULO_VENTANA);
    }//GEN-LAST:event_op1ActionPerformed



    private void op2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op2ActionPerformed
        agregarComponenteAlaLista(op2, K.Componente.FONDO);
    }//GEN-LAST:event_op2ActionPerformed

    private void op3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op3ActionPerformed
        agregarComponenteAlaLista(op3, K.Componente.HORA);
    }//GEN-LAST:event_op3ActionPerformed

    private void op4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op4ActionPerformed
        agregarComponenteAlaLista(op4, K.Componente.FECHA);
    }//GEN-LAST:event_op4ActionPerformed

    private void op5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op5ActionPerformed
        agregarComponenteAlaLista(op5, K.Componente.FONDO_BARRA_HORA);
    }//GEN-LAST:event_op5ActionPerformed

    private void op6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op6ActionPerformed
        agregarComponenteAlaLista(op6, K.Componente.FONDO_BARRA_MINUTO);
    }//GEN-LAST:event_op6ActionPerformed

    private void op7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op7ActionPerformed
        agregarComponenteAlaLista(op7, K.Componente.FONDO_BARRA_SEGUNDO);
    }//GEN-LAST:event_op7ActionPerformed

    private void op8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op8ActionPerformed
        agregarComponenteAlaLista(op8, K.Componente.BARRA_HORA);
    }//GEN-LAST:event_op8ActionPerformed

    private void op9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op9ActionPerformed
        agregarComponenteAlaLista(op9, K.Componente.BARRA_MINUTO);
    }//GEN-LAST:event_op9ActionPerformed

    private void op10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op10ActionPerformed
        agregarComponenteAlaLista(op10, K.Componente.BARRA_SEGUNDO);
    }//GEN-LAST:event_op10ActionPerformed

    private void op11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op11ActionPerformed
        agregarComponenteAlaLista(op11, K.Componente.TITULO_SOHUESPED);
    }//GEN-LAST:event_op11ActionPerformed

    private void op12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_op12ActionPerformed
        agregarComponenteAlaLista(op12, K.Componente.GPU);
    }//GEN-LAST:event_op12ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        op1.setSelected(false);
        op2.setSelected(false);
        op3.setSelected(false);
        op4.setSelected(false);
        op5.setSelected(false);
        op6.setSelected(false);
        op7.setSelected(false);
        op8.setSelected(false);
        op9.setSelected(false);
        op10.setSelected(false);
        op11.setSelected(false);
        op12.setSelected(false);
        componentes.clear();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        op1.setSelected(false);
        op2.setSelected(false);
        op3.setSelected(false);
        op4.setSelected(false);
        op5.setSelected(false);
        op6.setSelected(false);
        op7.setSelected(false);
        op8.setSelected(false);
        op9.setSelected(false);
        op10.setSelected(false);
        op11.setSelected(false);
        op12.setSelected(false);
        componentes.clear();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void lblAudioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAudioMouseClicked
        try {
            AudioFile a = new AudioFile(HoraAudio.RUTA_AUDIOS+"Button54.wav");
            a.play(true);
            Thread.sleep(a.getMiliSegundos());
            final Reproductor r  = HoraAudio.decirHora();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(r.getMiliSegundos()+100);
                        AudioFile a = new AudioFile(HoraAudio.RUTA_AUDIOS+"Button54.wav");
                        a.play(true);
                    } catch (            UnsupportedAudioFileException | IOException | LineUnavailableException | InterruptedException ex) {
                        Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    
                }
            }).start();
        } catch (InterruptedException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LineUnavailableException | IOException | UnsupportedAudioFileException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_lblAudioMouseClicked

    private void lblAudioMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAudioMouseExited
        // TODO add your handling code here:
    }//GEN-LAST:event_lblAudioMouseExited

    private void lblAudioMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAudioMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_lblAudioMousePressed

    private void lblAudioMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAudioMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_lblAudioMouseReleased

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        if(System.getProperty("os.name").contains("Windows")){
            try {
                javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
                Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Aplicacion().setVisible(true);
            }
        });
    }

    private void limpiarFormRecordatorio() {
        cboHora.setSelectedItem(Hora.getHora());
        cboMinuto.setSelectedItem(Hora.getMinuto());
        cboSegundo.setSelectedItem(Hora.getSegundo());
        men.setText("");
    }

    private synchronized void setColorEnPanelHora() {
        hora.setForeground(config.getColorHora());
        lblhor.setForeground(config.getColorHora());
        fecha.setForeground(config.getColorFecha());
        lblfec.setForeground(config.getColorFecha());
        panel.setBackground(config.getColorFondo());
        lblfnd.setForeground(config.getColorFondo());
        panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora Actual", 
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, 
                javax.swing.border.TitledBorder.DEFAULT_POSITION, 
                new java.awt.Font("Tahoma", 0, 11), 
                config.getColorTitulo()));
        
        barraHora.setBackground(config.getColorHoraBack());
        lblfbh.setForeground(config.getColorHoraBack());
        barraMinuto.setBackground(config.getColorMinutoBack());
        lblfbm.setForeground(config.getColorMinutoBack());
        barraSegundo.setBackground(config.getColorSegundoBack());
        lblfbs.setForeground(config.getColorSegundoBack());
        
        barraHora.setForeground(config.getColorHoraFront());
        lblbarhor.setForeground(config.getColorHoraFront());
        barraMinuto.setForeground(config.getColorMinutoFront());
        lblbarmin.setForeground(config.getColorMinutoFront());
        barraSegundo.setForeground(config.getColorSegundoFront());
        lblbarseg.setForeground(config.getColorSegundoFront());
        lblso.setForeground(config.getColorSistemaOperativo());
        gpu.setForeground(config.getColorGpu());
        lblsoh.setForeground(config.getColorSistemaOperativo());
        lblx.setForeground(config.getColorTitulo());
        lbltit.setForeground(config.getColorTitulo());
        lblgpu.setForeground(config.getColorGpu());
        setFondosDeLabels();
    }

    private void setPorcentajeTransparencia(float porcentaje) {
        float opacidad = porcentaje / 100;
        AWTUtilitiesWrapper.setWindowOpacity(this, (float)opacidad);
        Actualizar.opacidad(porcentaje);
        poropa.setText(String.valueOf((int)porcentaje)+"%");
    }

    private void establecerColor(K.Componente componente) {
        switch(componente){
            case TITULO_VENTANA:{
                panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora Actual", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), selector.getColor())); // NOI18N
//                ar_color.actualizarCampo("titulo", selector.getColor());
                Actualizar.colorDeComponente("titulo", selector.getColor());
                setColorEnPanelHora();
                break;
            }
            case FONDO:{
                setBackground(panel, "fondo");
                break;
            }
            case HORA:{
                setForegorund(hora, "hora");
                break;
            }
            case FECHA:{
                setForegorund(fecha, "fecha");
                break;
            }
            case FONDO_BARRA_HORA:{
                setBackground(barraHora, "horaBack");
                break;
            }
            case FONDO_BARRA_MINUTO:{
                setBackground(barraMinuto, "minutoBack");
                break;
            }
            case FONDO_BARRA_SEGUNDO:{
                setBackground(barraSegundo, "segundoBack");
                break;
            }
            case BARRA_HORA:{
                setForegorund(barraHora, "horaFront");
                break;
            }
            case BARRA_MINUTO:{
                setForegorund(barraMinuto, "minutoFront");
                break;
            }
            case BARRA_SEGUNDO:{
                setForegorund(barraSegundo, "segundoFront");
                break;
            }
            case TITULO_SOHUESPED:{
                setForegorund(lblso, "sistemaOperativo");
                break;
            }
            case GPU:{
                setForegorund(gpu, "gpu");
                break;
            }
        }
    }

    private void setFondosDeLabels() {
        Color inthor, intfec, intfon, intfbh, intfbm, intfbs, intbho, intbmi, intbse, intsis, inttit, intgep;
        
        inthor = config.getColorHora();
        intfec = config.getColorFecha();
        intfon = config.getColorFondo();
        intfbh = config.getColorHoraBack();
        intfbm = config.getColorMinutoBack();
        intfbs = config.getColorSegundoBack();
        intbho = config.getColorHoraFront();
        intbmi = config.getColorMinutoFront();
        intbse = config.getColorSegundoFront();
        intsis = config.getColorSistemaOperativo();
        inttit = config.getColorTitulo();
        intgep = config.getColorGpu();

        analizar(lblhor, inthor);
        analizar(lblfec, intfec);
        analizar(lblfnd, intfon);
        analizar(lblfbh, intfbh);
        analizar(lblfbm, intfbm);
        analizar(lblfbs, intfbs);
        analizar(lblbarhor, intbho);
        analizar(lblbarmin, intbmi);
        analizar(lblbarseg, intbse);
        analizar(lblsoh, intsis);
        analizar(lbltit, inttit);
        analizar(lblgpu, intgep);

    }

    private void analizar(JLabel lbl, Color color) {
        final int BLANCO, NEGRO;
        BLANCO = -1;
        NEGRO = -16777216;
        if(color.getRGB() == BLANCO){
            lbl.setForeground(Color.BLACK);
            lbl.setBackground(Color.WHITE);
        }else if(color.getRGB() == NEGRO){
            lbl.setForeground(Color.WHITE);
            lbl.setBackground(Color.BLACK);
        }else{
            lbl.setForeground(color.darker().darker());
            lbl.setBackground(color);
        }
    }

    private void iniciarHilos() {
        hHora.start();
        hBeep.start();
        hgpu.start();
    }

    private void inicializarComponentesGraficos() {
        setLocationRelativeTo(null);
        
        this.setLocation((int)config.getX(), (int)config.getY());

        Redimensionar.redimensionarFormulario(form_tema, false, "Cambio de Color");
        Redimensionar.redimensionarFormulario(Recordatorio, true, "Agregar Recordatorio");
        Redimensionar.redimensionarFormulario(form_log, true, "Mensajes de Recordatorio");

        form_log.setBounds(0, 0, 400, 500);
        form_log.setLocationRelativeTo(null);

        form_tema.setBounds(0, 0, (int) form_tema.getPreferredSize().getWidth() + 5, (int) form_tema.getPreferredSize().getHeight() + 30);
        form_tema.setLocationRelativeTo(null);
        setAlwaysOnTop(config.isSiempreEncima());

        lblx.setVisible(false);
        barraHora.setBorderPainted(false);
        barraMinuto.setBorderPainted(false);
        barraSegundo.setBorderPainted(false);

        barraMinuto.setOrientation(SwingConstants.VERTICAL);
        barraHora.setOrientation(SwingConstants.VERTICAL);
        setPorcentajeTransparencia(config.getOpacidad());
        nivelOpacidad.setValue((int)config.getOpacidad());
        app = new AppSystemtray(Ruta.ICONO);
    }

    private void getConfiguracionDesdeXML() {
        if(!new File(Ruta.CARPETA_CONFIGURACION).exists()){
            new File(Ruta.CARPETA_CONFIGURACION).mkdir();
        }
        
        if(!new File(Ruta.ARCHIVO_CONFIGURACION).exists()){
            crearXMLConfiguracion();
        }
        
        if(!new File(Ruta.ARCHIVO_RECORDATORIOS).exists()){
            crearXMLRecoratorios();
        }
        
        //en el constructor se rescata la informacion de los xml
        config = new Config();
    }

    private void addRecordatorioToXML(Recordatorio recordatorio) {
        Actualizar.addRecordatorio(recordatorio);    
    }

    private void crearXMLConfiguracion() {
        try {
            //creando tags necesarios
            Tag tConfig = new Tag("config");
            Tag tColor = new Tag("color");
            Tag tOpacidad = new Tag("opacidad");
            Tag tPorDefecto = new Tag("porDefecto");
            Tag tModificado = new Tag("modificado");
            Tag tPosicion = new Tag("posicion");
            Tag tSiempreEncima = new Tag("siempreEncima");
            
            //creando los tags de componentes de colores
            Tag tFondo = new Tag("componente");
            Tag tHora = new Tag("componente");
            Tag tFecha = new Tag("componente");
            Tag tTitulo = new Tag("componente");
            Tag tSegFront = new Tag("componente");
            Tag tSegBack = new Tag("componente");
            Tag tHorFront = new Tag("componente");
            Tag tHorBack = new Tag("componente");
            Tag tMinFront = new Tag("componente");
            Tag tMinBack = new Tag("componente");
            Tag tSstemaOperativo = new Tag("componente");
            Tag tGpu = new Tag("componente");
            
            //agregando los id's a los componentes
            tFondo.addAtributo("id", "fondo");
            tHora.addAtributo("id", "hora");
            tFecha.addAtributo("id", "fecha");
            tTitulo.addAtributo("id", "titulo");
            tSegFront.addAtributo("id", "segundoFront");
            tSegBack.addAtributo("id", "segundoBack");
            tHorFront.addAtributo("id", "horaFront");
            tHorBack.addAtributo("id", "horaBack");
            tMinFront.addAtributo("id", "minutoFront");
            tMinBack.addAtributo("id", "minutoBack");
            tSstemaOperativo.addAtributo("id", "sistemaOperativo");
            tGpu.addAtributo("id", "gpu");
            
            //agregando los colores a los componentes
            tFondo.addAtributo("color", "-16777216");
            tHora.addAtributo("color", "-256");
            tFecha.addAtributo("color", "-256");
            tTitulo.addAtributo("color", "-256");
            tSegFront.addAtributo("color", "-65536");
            tSegBack.addAtributo("color", "-16777216");
            tHorFront.addAtributo("color", "-65536");
            tHorBack.addAtributo("color", "-16777216");
            tMinFront.addAtributo("color", "-65536");
            tMinBack.addAtributo("color", "-16777216");
            tSstemaOperativo.addAtributo("color", "-3407872");
            tGpu.addAtributo("color", "-3407872");
            
            tColor.addAtributo("escogido","porDefecto");
            tOpacidad.addAtributo("nivel", "83");
            
            //agregando los componentes al tag por defecto
            tPorDefecto.addTagHijo(tFondo);
            tPorDefecto.addTagHijo(tHora);
            tPorDefecto.addTagHijo(tFecha);
            tPorDefecto.addTagHijo(tTitulo);
            tPorDefecto.addTagHijo(tSegFront);
            tPorDefecto.addTagHijo(tSegBack);
            tPorDefecto.addTagHijo(tHorFront);
            tPorDefecto.addTagHijo(tHorBack);
            tPorDefecto.addTagHijo(tMinFront);
            tPorDefecto.addTagHijo(tMinBack);
            tPorDefecto.addTagHijo(tSstemaOperativo);
            tPorDefecto.addTagHijo(tGpu);
            
            //agregando los componentes al tag modificado
            tModificado.addTagHijo(tFondo);
            tModificado.addTagHijo(tHora);
            tModificado.addTagHijo(tFecha);
            tModificado.addTagHijo(tTitulo);
            tModificado.addTagHijo(tSegFront);
            tModificado.addTagHijo(tSegBack);
            tModificado.addTagHijo(tHorFront);
            tModificado.addTagHijo(tHorBack);
            tModificado.addTagHijo(tMinFront);
            tModificado.addTagHijo(tMinBack);
            tModificado.addTagHijo(tSstemaOperativo);
            tModificado.addTagHijo(tGpu);
            
            tColor.addTagHijo(tPorDefecto);
            tColor.addTagHijo(tModificado);
            
            //estableciendo la posicion x e y de la ventana principal
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            this.setLocation((int) d.getWidth() - this.getWidth(), (int) d.getHeight() - this.getHeight());
            tPosicion.addAtributo("x", Double.toString(d.getWidth() - this.getWidth()));
            tPosicion.addAtributo("y", Double.toString(d.getHeight() - this.getHeight() - 40));
            
            //
            tSiempreEncima.addAtributo("valor", "true");
            
            tConfig.addTagHijo(tColor);
            tConfig.addTagHijo(tOpacidad);
            tConfig.addTagHijo(tPosicion);
            tConfig.addTagHijo(tSiempreEncima);
            
            JespXML.escribirXML(tConfig, new File(Ruta.ARCHIVO_CONFIGURACION));
        } catch (ParserConfigurationException | FileNotFoundException | TransformerException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void crearXMLRecoratorios() {
        try {
            JespXML.escribirXML(new Tag("recordatorios"), new File(Ruta.ARCHIVO_RECORDATORIOS));
        } catch (ParserConfigurationException | FileNotFoundException | TransformerException ex) {
            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private class HHora extends Thread{
        private int c = 0;
        private Mensajes m = new Mensajes();
        private String aux = "";
        int wea;
        @Override
        public void run(){
            while(true){
                
//                setColor();
                hora.setText(Hora.getHoraActual());
                barraHora.setValue(Integer.parseInt(Hora.getHora()));
                barraMinuto.setValue(Integer.parseInt(Hora.getMinuto()));
                barraSegundo.setValue(Integer.parseInt(Hora.getSegundo()));
                
                barraHora.setString("Hora ("+Math.round(barraHora.getPercentComplete()*100)+"%)");
                barraMinuto.setString("Minuto ("+Math.round(barraMinuto.getPercentComplete()*100)+"%)");
                barraSegundo.setString("Segundo ("+Math.round(barraSegundo.getPercentComplete()*100)+"%)");
                
                fecha.setText(Fecha.getNomDia()+" "+Fecha.getFecha(false, true));

                //ver lo de los recordatorios
//                for(int i = 0;i<cantidad;i++){
//                    if(ar.getValorDeConfiguracion("fecha"+(i+1)) != null){
//                        System.out.println();
//                        System.out.println();System.out.println();System.out.println();
//                        System.out.println();System.out.println();System.out.println();
//                        System.out.println();System.out.println();System.out.println();
//                        System.out.println();System.out.println();System.out.println();
//                        System.out.println("Fecha Actual: "+Fecha.getFecha(true, false));
//                        System.out.println("Fecha Archivo"+ar.getValorDeConfiguracion("fecha"+(i+1)));
//                        System.out.println("Hora Actual:"+Hora.getHoraActual());
//                        System.out.println("Hora Archivo"+ar.getValorDeConfiguracion("hora"+(i+1)));
//                        if(ar.getValorDeConfiguracion("fecha"+(i+1)).equalsIgnoreCase(Fecha.getFecha(true, false)) && ar.getValorDeConfiguracion("hora"+(i+1)).equalsIgnoreCase(Hora.getHoraActual())){
//                            aux = "["+Fecha.getFecha(false, true).replaceAll("/", " / ")+"] - ["+Hora.getHoraActual()+"] - ["+ar.getValorDeConfiguracion("mensaje"+(i+1))+"]";
//                            try {
//                                Archivo.escribirAAchivo(RUTA_LOG, aux, false);
//                                areaMensajes.setText(Archivo.leerArchivo(RUTA_LOG));
//                            } catch (IOException ex) {
//                                Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
//                            }
//
//                            if(!form_log.isVisible()){
//                                form_log.setVisible(true);
//                            }
//
//                            hBeep.setEstado(true);
//
//                            ar.comentarCampo("hora"+(i+1));
//                            ar.comentarCampo("mensaje"+(i+1));
//                            ar.comentarCampo("fecha"+(i+1));
//                            ar.actualizarCampo("cantidad", Integer.toString(Integer.parseInt(ar.getValorDeConfiguracion("cantidad"))-1));
//                        }
//                    }
//                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    

    private class HBeep extends Thread{
        private boolean estado = false;

        @Override
        public void run(){
            while(true){
                if(estado){
                    Toolkit.getDefaultToolkit().beep();
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        public void setEstado(boolean e){
            estado = e;
        }
    }

    private class HGpu extends Thread{
        @Override
        public void run(){
            while(true){
                if(Ejecutar.ejecutarComandoLinux("nvidia-settings -q [gpu:0]/GPUCoreTemp") == null){
                    gpu.setText("");
                    break;
                }
                gpu.setText(Ejecutar.ejecutarComandoLinux("nvidia-settings -q [gpu:0]/GPUCoreTemp")+"º");
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame Recordatorio;
    private javax.swing.JTextArea areaMensajes;
    private javax.swing.JProgressBar barraHora;
    private javax.swing.JProgressBar barraMinuto;
    private javax.swing.JProgressBar barraSegundo;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cboHora;
    private javax.swing.JComboBox cboMinuto;
    private javax.swing.JComboBox cboSegundo;
    private javax.swing.JLabel fecha;
    private datechooser.beans.DateChooserCombo fechaChooser;
    private javax.swing.JFrame form_log;
    private javax.swing.JFrame form_opa;
    private javax.swing.JFrame form_tema;
    private javax.swing.JLabel gpu;
    private javax.swing.JLabel hora;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblAudio;
    private javax.swing.JLabel lblbarhor;
    private javax.swing.JLabel lblbarmin;
    private javax.swing.JLabel lblbarseg;
    private javax.swing.JLabel lblfbh;
    private javax.swing.JLabel lblfbm;
    private javax.swing.JLabel lblfbs;
    private javax.swing.JLabel lblfec;
    private javax.swing.JLabel lblfnd;
    private javax.swing.JLabel lblgpu;
    private javax.swing.JLabel lblhor;
    private javax.swing.JLabel lblso;
    private javax.swing.JLabel lblsoh;
    private javax.swing.JLabel lbltit;
    private javax.swing.JLabel lblx;
    private javax.swing.JTextArea men;
    private javax.swing.JSlider nivelOpacidad;
    private javax.swing.JRadioButton op1;
    private javax.swing.JRadioButton op10;
    private javax.swing.JRadioButton op11;
    private javax.swing.JRadioButton op12;
    private javax.swing.JRadioButton op2;
    private javax.swing.JRadioButton op3;
    private javax.swing.JRadioButton op4;
    private javax.swing.JRadioButton op5;
    private javax.swing.JRadioButton op6;
    private javax.swing.JRadioButton op7;
    private javax.swing.JRadioButton op8;
    private javax.swing.JRadioButton op9;
    private javax.swing.JPanel panel;
    private javax.swing.JLabel poropa;
    private javax.swing.JColorChooser selector;
    // End of variables declaration//GEN-END:variables

    private void setBackground(java.awt.Component componente, String id){
        componente.setBackground(selector.getColor());
//        ar_color.actualizarCampo(campoDeArchivo, selector.getColor());
        Actualizar.colorDeComponente(id, selector.getColor());
        setColorEnPanelHora();
    }

    private void setForegorund(java.awt.Component componente, String id){
        componente.setForeground(selector.getColor());
//        ar_color.actualizarCampo(campoDeArchivo, selector.getColor());
        Actualizar.colorDeComponente(id, selector.getColor());
        setColorEnPanelHora();
    }

    private class AppSystemtray {
        private final String TITULO = "JReloj";
        private TrayIcon trayicon;
        private SystemTray tray;
        private Image icono;
        private PopupMenu popup;

        public AppSystemtray(String rutaDelIcono){
            if(SystemTray.isSupported()){
                tray = SystemTray.getSystemTray();
                popup = new PopupMenu();

                MenuItem opTema = new MenuItem("Cambiar Tema");
                MenuItem opPredefinido = new MenuItem("Cargar Tema Predeterminado");
                MenuItem opAviso = new MenuItem("Recordatorio");
                MenuItem opAlarma = new MenuItem("Apagar Sonido Alarma");
                final MenuItem opEncima = new MenuItem("Siempre Visible "+(config.isSiempreEncima()?"OFF":"ON"));
                MenuItem opLog = new MenuItem("Mostrar Recordatorios");
                MenuItem opCambiarPredefinido = new MenuItem("Dejar tema actual como Predeterminado");
                MenuItem optSalir = new MenuItem("Cerrar Reloj");
                MenuItem opOpacidad = new MenuItem("Nivel de Opacidad");
                MenuItem opPreferencias = new MenuItem("Preferencias");

                opPreferencias.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Preferencias");
                    }
                });
                
                opOpacidad.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        Redimensionar.redimensionarFormulario(form_opa, true, "Nivel de Opacidad");
                        form_opa.setVisible(true);
                    }
                });

                opLog.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        try {
                            areaMensajes.setText(Archivo.leerArchivo(Ruta.ARCHIVO_RECORDATORIOS));
                            form_log.setVisible(true);
                        } catch (IOException ex) {
                            Logger.getLogger(Aplicacion.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                });

                opCambiarPredefinido.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
//                        if(Mensajes.mensajePreguntaSiNo("¿Realmente desea cambiar el tema Predeterminado?") == Mensajes.si){
//                            ar_color_predefinido.actualizarCampo("fondo", ar_color.getValorDeConfiguracion("fondo"));
//                            ar_color_predefinido.actualizarCampo("hora", ar_color.getValorDeConfiguracion("hora"));
//                            ar_color_predefinido.actualizarCampo("fecha", ar_color.getValorDeConfiguracion("fecha"));
//                            ar_color_predefinido.actualizarCampo("titulo", ar_color.getValorDeConfiguracion("titulo"));
//                            ar_color_predefinido.actualizarCampo("sFront", ar_color.getValorDeConfiguracion("sFront"));
//                            ar_color_predefinido.actualizarCampo("sBack", ar_color.getValorDeConfiguracion("sBack"));
//                            ar_color_predefinido.actualizarCampo("hFront", ar_color.getValorDeConfiguracion("hFront"));
//                            ar_color_predefinido.actualizarCampo("hBack", ar_color.getValorDeConfiguracion("hBack"));
//                            ar_color_predefinido.actualizarCampo("mFront", ar_color.getValorDeConfiguracion("mFront"));
//                            ar_color_predefinido.actualizarCampo("mBack", ar_color.getValorDeConfiguracion("mBack"));
//                            ar_color_predefinido.actualizarCampo("so", ar_color.getValorDeConfiguracion("so"));
//                            Mensajes.mensajeInformacion("Tema predeterminado cambiado con éxito");
//                        }
                    }
                });

                opEncima.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        if(opEncima.getLabel().contains("Off")){
                            setAlwaysOnTop(false);
                            opEncima.setLabel("Siempre Visible On");
                            Actualizar.siempreEncima(false);
                        }else{
                            setAlwaysOnTop(true);
                            opEncima.setLabel("Siempre Visible Off");
                            Actualizar.siempreEncima(true);
                        }
                    }
                });

                opAlarma.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        hBeep.setEstado(false);
                    }
                });

                opPredefinido.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        Actualizar.dejarTemaPorDefecto();
                        setColorEnPanelHora();
                    }
                });

                opAviso.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        cboHora.setSelectedItem(Hora.getHora());
                        cboMinuto.setSelectedItem(Hora.getMinuto());
                        cboSegundo.setSelectedItem(Hora.getSegundo());

                        Recordatorio.setVisible(true);
                    }
                });

                opTema.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        form_tema.setVisible(true);
                    }
                });

                optSalir.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        int op = Mensajes.mensajePreguntaSiNo
                                ("¿Esta seguro que desea Salir de la Aplicación JReloj?");
                        if(op==Mensajes.si){
                            System.exit(0);
                        }
                    }
                });
                /*MenuItem opTema = new MenuItem("Cambiar Tema");
                MenuItem opPredefinido = new MenuItem("Cargar Tema Predeterminado");
                MenuItem opAviso = new MenuItem("Recordatorio");
                MenuItem opAlarma = new MenuItem("Apagar Sonido Alarma");
                JCheckBoxMenuItem opEncima = new JCheckBoxMenuItem("Siempre Visible");
                MenuItem opLog = new MenuItem("Mostrar Recordatorios");
                MenuItem opCambiarPredefinido = new MenuItem("Dejar tema actual como Predeterminado");
                MenuItem optSalir = new MenuItem("Cerrar Reloj");*/

                popup.add(opOpacidad);
                popup.addSeparator();
                popup.add(opTema);
                popup.add(opPredefinido);
                popup.add(opCambiarPredefinido);
                popup.addSeparator();
                popup.add(opAviso);
                popup.add(opLog);
                popup.add(opAlarma);
                popup.addSeparator();
                popup.add(opEncima);
                popup.add(opPreferencias);
                popup.addSeparator();
                popup.add(optSalir);


                icono = Toolkit.getDefaultToolkit().getImage(rutaDelIcono);
                trayicon = new TrayIcon(icono, TITULO, popup);
                trayicon.setImageAutoSize(true);

                try {
                    tray.add(trayicon);
                } catch (AWTException e1) {
                    System.out.println(e1.getStackTrace());
                }

            }
        }
    }

    private void agregarComponenteAlaLista(javax.swing.JRadioButton op, K.Componente constante){
        if(op.isSelected()) componentes.add(constante);
        else componentes.remove(componentes.indexOf(constante));
    }

}
